package com.example.demo.程序员面试金典;

import com.example.demo.leetcode100题.ListNode;

/**
 * @author：zzc
 * @date: 2022/9/7
 */
public class 移除重复节点 {

    /**
     * Definition for singly-linked list.
     * public class ListNode {
     *     int val;
     *     ListNode next;
     *     ListNode(int x) { val = x; }
     * }
     */
    class Solution {

        public ListNode removeDuplicateNodes(ListNode head) {
            if (head == null  ) {
                return null;
            }

            ListNode currentNode = head;
            while (currentNode.next != null) {
                if (currentNode.val == currentNode.next.val) {
                    currentNode.next = currentNode.next.next;
                }else {
                    currentNode = currentNode.next;
                }
            }
            return currentNode;
        }
    }


}
